Completed
Push — master ( 6b7b93...3c2c59 )
by Maxence
02:59
created

actions.changeMemberLevel   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
nc 2
nop 2
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: resultMembers */
34
/** global: resultCircles */
35
/** global: curr */
36
/** global: api */
37
38
39
var actions = {
40
41
42
	changeMemberLevel: function (member, level) {
43
		if (parseInt(level) === define.levelOwner) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
			actions.changeMemberOwner(member);
45
			return;
46
		}
47
		api.levelMember(curr.circle, member, level, resultMembers.levelMemberResult);
48
		nav.circlesActionReturn();
49
	},
50
51
52
	changeMemberOwner: function (member) {
53
		OC.dialogs.confirm(
54
			t('circles', 'Are you sure you want to transfer your Owner rights ?', [member]),
55
			t('circles', 'This action is irreversible'),
56
			function (e) {
57
				if (e === true) {
58
					api.levelMember(curr.circle, member, define.levelOwner, resultMembers.levelMemberResult);
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
59
					nav.circlesActionReturn();
60
				}
61
			});
62
	},
63
64
65
	changeMemberStatus: function (member, value) {
66
		if (value === 'remove_member' || value === 'dismiss_request') {
67
			api.removeMember(curr.circle, member, resultMembers.removeMemberResult);
68
		}
69
		if (value === 'accept_request') {
70
			api.addMember(curr.circle, member, resultMembers.addMemberResult);
71
		}
72
	},
73
74
75
	selectCircle: function (circle_id) {
76
		curr.searchUser = '';
77
		elements.addMember.val('');
78
		elements.linkCircle.val('');
79
80
		nav.circlesActionReturn();
81
		api.detailsCircle(circle_id, resultCircles.selectCircleResult);
82
	},
83
84
85
	unselectCircle: function (circle_id) {
86
		elements.mainUIMembersTable.emptyTable();
87
		elements.navigation.children(".circle[circle-id='" + circle_id + "']").remove();
88
		elements.emptyContent.show(800);
89
		elements.mainUI.fadeOut(800);
90
91
		curr.circle = 0;
92
		curr.circleLevel = 0;
93
	},
94
95
96
	saveSettings: function () {
97
		data = {
0 ignored issues
show
Bug introduced by
The variable data seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.data.
Loading history...
98
			allow_links: (elements.settingsLink.is(":checked")),
99
			allow_links_auto: (elements.settingsLinkAuto.is(":checked")),
100
			allow_links_files: (elements.settingsLinkFiles.is(":checked"))
101
		};
102
103
		api.settingsCircle(curr.circle, data, settings.saveSettingsResult);
0 ignored issues
show
Bug introduced by
The variable settings seems to be never declared. If this is a global, consider adding a /** global: settings */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
104
	},
105
106
	/**
107
	 *
108
	 * @param search
109
	 */
110
	searchMembersRequest: function (search) {
111
112
		if (curr.searchUser === search) {
113
			return;
114
		}
115
116
		curr.searchUser = search;
117
118
		$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees',
119
			{
120
				format: 'json',
121
				search: search,
122
				perPage: 200,
123
				itemType: 'principals'
124
			}, resultMembers.searchMembersResult);
125
	},
126
127
128
	getStringTypeFromType: function (type) {
129
		switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
130
			case '1':
131
				return t('circles', 'Personal circle');
132
			case '2':
133
				return t('circles', 'Hidden circle');
134
			case '4':
135
				return t('circles', 'Private circle');
136
			case '8':
137
				return t('circles', 'Public circle');
138
		}
139
140
		return t('circles', 'Circle');
141
	},
142
143
144
	/**
145
	 *
146
	 */
147
	onEventNewCircle: function () {
148
		curr.circle = 0;
149
		curr.circleLevel = 0;
150
151
		elements.circlesList.children('div').removeClass('selected');
152
		elements.emptyContent.show(800);
153
		elements.mainUI.fadeOut(800);
154
	},
155
156
157
	/**
158
	 *
159
	 */
160
	onEventNewCircleName: function () {
161
		this.onEventNewCircle();
162
		nav.displayOptionsNewCircle((elements.newName.val() !== ''));
163
	},
164
165
166
	/**
167
	 *
168
	 */
169
	onEventNewCircleType: function () {
170
		this.onEventNewCircle();
171
		elements.newTypeDefinition.children('div').fadeOut(300);
172
		var selectedType = elements.newType.children('option:selected').val();
173
		if (selectedType === '') {
174
			elements.newType.addClass('select_none');
175
		}
176
		else {
177
			elements.newType.removeClass('select_none');
178
			$('#circles_new_type_' + selectedType).fadeIn(
179
				300);
180
		}
181
	}
182
183
184
};
185